﻿#region Header
/*
 * name：User
 * author：Kain
 * date：11/25/2010 11:28:36 AM
 *********************************************
 * History:
 * $Header$
 * $History$
 */
#endregion

#region imported namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Security.Principal;
using System.Runtime.Serialization;
#endregion

namespace Cherry.Agile.Security
{
    /// <summary>
    /// 用户信息
    /// </summary>
    [Serializable]
    [DataContract]
    public class User:IIdentity  
	{
        const string ANONYMOUS_USER = "__ANONYMOUS";

        /// <summary>
        /// 构造函数
        /// </summary>
        public User():this(ANONYMOUS_USER){

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userName">用户登录名称</param>
        public User(string userName)
        {
            Identity = userName;
        }

        /// <summary>
        /// 用户ID
        /// </summary>
        [DataMember]
        public int ID { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [DataMember]
        public string Password { get; set; }

        /// <summary>
        /// 用户身份标识
        /// </summary>
        [DataMember]
        public string Identity { get; set; }

        /// <summary>
        /// 用户类型
        /// </summary>
        [DataMember]
        public int UserType { get; set; }
        
        /// <summary>
        /// 用户的默认语言环境
        /// </summary>
        [DataMember]
        public string Cultural { get; set; }

        /// <summary>
        /// 用户真实名称
        /// </summary>
        [DataMember]
        public string FullName { get; set; }

        /// <summary>
        /// 角色
        /// </summary>
        [DataMember]
        public Role[] Roles { 
            get; 
            set; 
        }
        
        /// <summary>
        /// 辅助信息
        /// </summary>
        [DataMember]
        public string Tag { get; set; }

        /// <summary>
        /// 组织
        /// </summary>
        [DataMember]
        public Organization[] Organizations { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        [DataMember]
        public int Status { get; set; }

        string IIdentity.AuthenticationType
        {
            get { return string.Empty; }
        }

        bool IIdentity.IsAuthenticated
        {
            get { return this.Identity != ANONYMOUS_USER;}
        }

        string IIdentity.Name
        {
            get { return this.Identity; }
        }
    }
}
